<?php
//power by huanran.zhao
//QQ: 523994553
//2013-04-18
class FunctionsApp extends CommonApp//公共函数
{
	/**
	 * 点击浏览量+1
	 * @method AJAX->$_POST
	 * @param string param 参数(table=xxx&field=xxx&id=xxx)
	 * @return echo string
	 */
	public function setHitAct(){
		$param = I('request.params');
		if(!$param=My::decode($param))
			exit("参数错误(param)");
		parse_str($param,$param);
		if(empty($param['table']))
			exit("参数有误(table)");
		if(empty($param['field']))
			exit("参数有误(field)");
		if(empty($param['id']) OR !My::is_id($param['id']))
			exit("参数有误(id)");
		//$value = I('request.value');
		$where = "id={$param['id']}";
		DB($param['table'])->where($where)->clear()->setInc('field');
		//返回+1后的字段值
		exit(DB($param['table'])->where($where)->cache()->getField($param['field']));
	}

	/**
	 * 添加顶/踩(喜欢/一般)(1/0)
	 * @data array $data 参数数组(array('title'=>'标题', 'type'=>'fav', 'idid'=>'表中的id', 'table'=>'数据表', 'image'=>'图片') )
	 * @return array
	 */
	public function addLikeAct(){
		//处理param参数
		$param = I('request.param');
		if(!$param=My::decode($param))
			exit("参数错误(param)");
		parse_str($param,$param);
		if(empty($param['table']))
			exit("参数有误(table)");
		if(empty($param['idid']) OR !My::is_id($param['idid']))
			exit("参数有误(idid)");
		//value值(1:喜欢,0:一般)
		$param['value'] = (My::arr2var($_POST,'value')==1)?1:0;
		//添加
		echo M('admin.fav')->addLike($param);
	}
	public function getLikeAct(){
		$data['table'] = I('post.table');
		$data['type'] = I('post.type');
		$data['idid'] = (int)My::arr2var($_POST,'idid');
		echo json_encode(DB('fav')->field("count(`id`) as `count`, sum(`value`) as `sum`")->where("idid={$data['idid']} AND `type`='{$data['type']}' AND `table`='{$data['table']}'")->cache()->find());
	}
	
	//获取验证码
	public function getVerifyCodeAct(){
		$config = array('imageW'=>100,'imageH'=>30,'fontSize'=>14,'useNoise'=>false,'fontttf'=>'5.ttf','length'=>4);
		$verify = new Verify($config);
		$verify->entry();
	}
	
}